//
//  HWRegistTypeCell.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/2/7.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWRegistTypeCell: UICollectionViewCell {
    var bgView:UIView!
    var rankLabel:UILabel!
    var userLabel:UILabel!
    var lowUserLabel:UILabel!
    
    var zeroLine:UIView!
    var firstLine:UIView!
    var secondLine:UIView!
    var fourLine:UIView!
    var bottomLine:UIView!
    var indexPath:IndexPath? {
        didSet {
            self.layoutIfNeeded()
            if (indexPath?.row ?? 0) % 2 == 0 {
                bgView.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                zeroLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                firstLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                secondLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                fourLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
            }else {
                bgView.backgroundColor = .white
                zeroLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                firstLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                secondLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                fourLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
            }
            
            rankLabel.font = .systemFont(ofSize: 14*widthScale)
            rankLabel.textColor = .colorWithAlphaHexString(hexString: "#000000", alpha: 0.65)
            userLabel.font = .systemFont(ofSize: 14*widthScale)
            userLabel.textColor = .colorWithAlphaHexString(hexString: "#000000", alpha: 0.65)
            lowUserLabel.font = .systemFont(ofSize: 14*widthScale)
            lowUserLabel.textColor = .colorWithAlphaHexString(hexString: "#000000", alpha: 0.65)
            if indexPath?.row == 0 {
                bgView.addCorner(conrners: [.topLeft,.topRight], radius: 4*widthScale)
                zeroLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                firstLine.backgroundColor = .white
                secondLine.backgroundColor = .white
                fourLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
                rankLabel.font = .boldSystemFont(ofSize: 14*widthScale)
                rankLabel.textColor = .colorWithAlphaHexString(hexString: "#000000", alpha: 0.85)
                userLabel.font = .boldSystemFont(ofSize: 14*widthScale)
                userLabel.textColor = .colorWithAlphaHexString(hexString: "#000000", alpha: 0.85)
                lowUserLabel.font = .boldSystemFont(ofSize: 14*widthScale)
                lowUserLabel.textColor = .colorWithAlphaHexString(hexString: "#000000", alpha: 0.85)
                
            }else if indexPath?.row == 8{
                bgView.addCorner(conrners: [.bottomLeft,.bottomRight], radius: 4*widthScale)
            }else {
                bgView.addCorner(conrners: [.topLeft,.topRight,.bottomLeft,.bottomRight], radius: 0)
                
            }
        }
    }
    
    var model:HWRegistTypeListModel? {
        didSet {
            rankLabel.text = model?.reg_type
            userLabel.text = "\(model?.count ?? 0)"
            lowUserLabel.text = model?.bfb
        }
    }
    var rechargeTypeListModel:HWRechargeTypeListModel? {
        didSet{
            rankLabel.text = rechargeTypeListModel?.payment
            userLabel.text = "\(rechargeTypeListModel?.count ?? 0)"
            lowUserLabel.text = rechargeTypeListModel?.bfb
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWRegistTypeCell {
    private func initUI() -> Void {
        bgView = UIView()
        contentView.addSubview(bgView)
        
        zeroLine = UIView()
        zeroLine.backgroundColor = .colorWithHexString(hexString: "#F5F5F5")
        bgView.addSubview(zeroLine)
        
        rankLabel = HWLabel.createBoldLabel(title: "渠道", color: "#000000", font: 14*widthScale)
        bgView.addSubview(rankLabel)
        
        firstLine = UIView()
        firstLine.backgroundColor = .colorWithHexString(hexString: "#F5F5F5")
        bgView.addSubview(firstLine)
        
        userLabel = HWLabel.createBoldLabel(title: "注册量", color: "#000000", font: 14*widthScale)
        bgView.addSubview(userLabel)
        
        secondLine = UIView()
        secondLine.backgroundColor = .colorWithHexString(hexString: "#F5F5F5")
        bgView.addSubview(secondLine)
        
        lowUserLabel = HWLabel.createBoldLabel(title: "占比", color: "#000000", font: 14*widthScale)
        bgView.addSubview(lowUserLabel)
        
        fourLine = UIView()
        fourLine.backgroundColor = .colorWithHexString(hexString: "#F5F5F5")
        bgView.addSubview(fourLine)
        
        bottomLine = UIView()
        bottomLine.backgroundColor = .colorWithHexString(hexString: "#F5F5F5")
        bgView.addSubview(bottomLine)
    }
    
    private func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        zeroLine.snp.makeConstraints { make in
            make.width.equalTo(1)
            make.top.bottom.equalToSuperview()
            make.left.equalTo(0)
        }
        
        rankLabel.snp.makeConstraints { make in
            make.left.equalTo(8*widthScale)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(131*widthScale)
        }
        
        firstLine.snp.makeConstraints { make in
            make.width.equalTo(1)
            make.top.bottom.equalToSuperview()
            make.left.equalTo(131*widthScale)
        }
        
        userLabel.snp.makeConstraints { make in
            make.left.equalTo(firstLine.snp.right).offset(9*widthScale)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(108*widthScale)
        }
        
        secondLine.snp.makeConstraints { make in
            make.width.equalTo(1)
            make.top.bottom.equalToSuperview()
            make.left.equalTo(239*widthScale)
        }
        
        lowUserLabel.snp.makeConstraints { make in
            make.left.equalTo(secondLine.snp.right).offset(10*widthScale)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(96*widthScale)
        }
        
        fourLine.snp.makeConstraints { make in
            make.width.equalTo(1)
            make.top.bottom.equalToSuperview()
            make.right.equalTo(0)
        }
        
        bottomLine.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
}
